package com.tgm.controller;
import com.tgm.domain.common.PageResult;
import com.tgm.domain.common.Result;
import com.tgm.domain.dto.ConsumptionQueryDTO;
import com.tgm.domain.dto.ExcelExportQuery;
import com.tgm.domain.dto.HeatMapDTO;
import com.tgm.domain.vo.ConsumptionShowVO;
import com.tgm.domain.vo.HeatMapVO;
import com.tgm.service.ConsumptionRecordService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 消费记录表(ConsumptionRecord)表控制层
 *
 * @author makejava
 * @since 2025-10-20 20:59:24
 */
@RestController
@RequestMapping("/consumptionRecord")
public class ConsumptionRecordController{
    @Autowired
    private ConsumptionRecordService consumptionRecordService;

    /*
    导入数据
     */
    @PostMapping("/import")
    public Result importData(@RequestBody MultipartFile file) throws IOException {
        System.out.println("开始执行导入数据");
        return consumptionRecordService.importData(file);
    }

    /*
    条件分页查询消费记录
     */
    @GetMapping("/list")
    public Result list(ConsumptionQueryDTO consumptionQueryDTO){
        System.out.println("请求参数："+consumptionQueryDTO);
        PageResult<ConsumptionShowVO> pageResult = consumptionRecordService.queryByPage(consumptionQueryDTO);
        return Result.success(pageResult);
    }

    /*
    获取热力图数据
     */
    @GetMapping("/heatMap")
    public Result getHeatMapData(HeatMapDTO param) {
        List<HeatMapVO> heatData = consumptionRecordService.statHeatMapData(param);
        return Result.success(heatData);
    }

    /**
     * 导出消费数据为Excel
     */
    @PostMapping("/excel")
    public void exportToExcel(
            @RequestBody ExcelExportQuery query,
            HttpServletResponse response
    ) throws IOException {
        consumptionRecordService.exportConsumptionExcel(query, response);
    }
}

